#include <barrier>
#include <iostream>
#include <thread>
using namespace std;
int main() {
    std::barrier b(5);                 // 5 个人同步
    auto job = [&](int id) {
        std::cout << id << std::endl;  // 先输出 1~5
        std::this_thread::sleep_for(std::chrono::seconds(id));
        // 1、让5个线程都运行到此处后暂停，等都到齐了再继续往下运行
        b.arrive_and_wait();           // 等齐
        std::cout << id << " go" << std::endl;
    };

    thread t1(job,1)  ;
    thread t2(job,2)  ;
    thread t3(job,3)  ;
    thread t4(job,4)  ;
    thread t5(job,5)  ;
    t1.join();
    t2.join();
    t3.join();
    t4.join();
    t5.join();  
    return 0;
}